package com.sba.core.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import org.springframework.stereotype.Service;

import com.sba.core.domain.Dictionary;
import com.sba.core.repository.DictionaryRepository;
import com.sba.core.service.DictionaryService;

/**
 * 
 * @author feiliming
 *
 */
@Service
public class DictionaryServiceImpl extends BaseServiceImpl<Dictionary> implements DictionaryService {
	
	//private static final Logger log = LoggerFactory.getLogger(DictionaryServiceImpl.class);
	
	@Autowired
	DictionaryRepository dictionaryRepository;

	@Override
	public List<Dictionary> getDictionaries() {
		Order typeOrder = new Order(Direction.ASC, "type");
		Order sortOrder = new Order(Direction.ASC, "sort");
		Sort sort = new Sort(typeOrder, sortOrder);
		return dictionaryRepository.findByIsDelete(0, sort);
	}

	@Override
	public List<Dictionary> getDictionaries(String type) {
		Order typeOrder = new Order(Direction.ASC, "type");
		Order sortOrder = new Order(Direction.ASC, "sort");
		Sort sort = new Sort(typeOrder, sortOrder);
		return dictionaryRepository.findByTypeAndIsDelete(type, 0, sort);
	}

	@Override
	public List<Dictionary> getDictionaries(Long parentId) {
		Order typeOrder = new Order(Direction.ASC, "type");
		Order sortOrder = new Order(Direction.ASC, "sort");
		Sort sort = new Sort(typeOrder, sortOrder);
		return dictionaryRepository.findByParentIdAndIsDelete(parentId, 0, sort);
	}

	@Override
	public List<Dictionary> getDictionaries(Long parentId, String type) {
		Order typeOrder = new Order(Direction.ASC, "type");
		Order sortOrder = new Order(Direction.ASC, "sort");
		Sort sort = new Sort(typeOrder, sortOrder);
		return dictionaryRepository.findByParentIdAndTypeAndIsDelete(parentId, type, 0, sort);
	}

}
